import { request } from '@inbiz/utils';
import type { InbizHistory } from '@inbiz/utils';
import { getEditor } from '@inbiz/utils';
import { routerPrefix } from 'InbizConfig';
export async function uploadImage(params: any, data: any) {
  return request(
    `/inbiz/api/services/front/engines/v${InbizConfig.API_VERSION}/common/uploadImageByStaticFile`,
    {
      method: 'POST',
      requestType: 'form',
      data,
      params,
    },
  );
}

export const openUrl = (props: any, history: InbizHistory) => {

  if (getEditor()) {
    return;
  }
  if (props.linkType == 'in' || props.linkType === undefined) {
    if (!props.page) {
      return;
    }
    let router = props.page.split(',');
    router = router.length > 0 ? router[0] : '';
    // const cleanRouter = router.replace('page/', '');
    // router = window.location.hash.includes('/page/') ? cleanRouter : router;
    history.push(routerPrefix + router);
  } else {
    if (!props.url) {
      return;
    }
    window.open(props.url);
  }
};
